package com.dd.auth.controller;

import com.dd.auth.service.UserService;
import com.dd.auth.vo.User;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "测试类", tags = {"测试接口"})
@RestController
@RequestMapping("index")
public class IndexController {

    private final UserService userService;

    @Autowired
    public IndexController(UserService userService) {
        this.userService = userService;
    }

    @ApiOperation(value = "添加一部电影", notes = "测试方法")
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    @ApiResponses(value = {@ApiResponse(code = 1000, message = "成功"),
            @ApiResponse(code = 1001, message = "失败"),
            @ApiResponse(code = 1002, response = String.class, message = "缺少参数")})
    public String index() {
        return "Hello,World!";
    }

    @ApiOperation(value = "getAllUser", notes = "获取所有", httpMethod = "GET")
    @ApiResponses(value = {@ApiResponse(code = 1000, message = "成功"),
            @ApiResponse(code = 1001, message = "失败"),
            @ApiResponse(code = 1002, response = List.class, message = "缺少参数")})
    @RequestMapping(value = "/getAllUser", method = RequestMethod.GET)
    public @ResponseBody
    List<User> getAllUser() {
        List<User> allUser = userService.getAllUser();
        return allUser;
    }

    @ApiOperation(value = "getUserBySex", notes = "通过性别获取user", httpMethod = "GET")
    @ApiResponses(value = {@ApiResponse(code = 1000, message = "成功"),
            @ApiResponse(code = 1001, message = "失败"),
            @ApiResponse(code = 1002, response = String.class, message = "缺少参数")})
    @RequestMapping(value = "/getuserbysex", method = RequestMethod.GET)
    public List<User> getUserBySex(@ApiParam("性别") @RequestParam(value = "sex") String sex) {
        List<User> allUser = userService.getUserBySex(sex);
        return allUser;
    }
}